package com.Servlet;

import java.io.IOException;
import java.sql.SQLException;
import java.util.HashMap;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jdbc.Jdbc;

/**
 * Servlet implementation class workcontract
 */
@WebServlet("/workcontract")
public class workcontract extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public workcontract() {
		
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		String cid = request.getParameter("contractid");
		String id = request.getParameter("id");
		String cname = request.getParameter("chinesename");
		String ename = request.getParameter("englishname");
		String sex = request.getParameter("sex");
		String birthday = request.getParameter("birthday");
		String coursename = request.getParameter("coursename");
		String totalclass = request.getParameter("totalclass");
		String restclass = request.getParameter("restclass");
		String tuition = request.getParameter("tuition");
		String chargestate = request.getParameter("chargestate");
		String signtype = request.getParameter("signtype");
		String counselor = request.getParameter("counselor");
		String pcounselor = request.getParameter("phonecounselor");
		String cteacher = request.getParameter("chineseteacher");
		String eteacher = request.getParameter("englishteacher");
		String username = (String) request.getSession().getAttribute("username");

		String update="update contract set contractid='"+cid+"',chinesename='"+cname+"',englishname='"+ename+"',sex='"+sex+"',birthday='"+birthday+"',coursename='"+coursename+"',totalclass='"+totalclass+"',restclass='"+restclass+"',tuition='"+tuition+"',"
				+ "chargestate='"+chargestate+"',signtype='"+signtype+"',counselor='"+counselor+"',phonecounselor='"+pcounselor+"',chineseteacher='"+cteacher+"',englishteacher='"+eteacher+"',username='"+username+"' where id='"+id+"'";
		System.out.println(update);
		Jdbc j1 = null;

		try {
			j1 = new Jdbc(update);

		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        //在添加了合同信息后，就要给每个合同的学生添加到一个签到表中，以便后来再检查该学生的签到记录
		//签到表为check_info,并且在其中记录签到的日期
		
		request.getRequestDispatcher("showsuccess.jsp").forward(request, response);

	}

}
